home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / plotting / pcgplots / gptutil.cpp < prev    next >
C/C++ Source or Header  |  1992-04-24  |  4KB  |  179 lines

  1. // GptUtil.cpp - utility c routines
  2. // copyright 1992 Pittsburgh Supercomputing Center
  3. #include "gpt.h"
  4. #include <stdio.h>
  5. // ****** SeparateFile
  6. // separate srcFileName into a DestFilePath and DestFileName
  7. #if  (sizeof( int) <= 16)
  8. #endif
  9.  
  10. void SeparateFile(LPSTR lpDestPath, LPSTR lpDestFileName, LPSTR lpDestExt,
  11.                       LPSTR lpSrcFileName)
  12.     {
  13.     LPSTR lpTmp;
  14.     BYTE cTmp;
  15.  
  16.     lpTmp = lpSrcFileName + (long)lstrlen(lpSrcFileName);
  17.     while (*lpTmp != ':' && *lpTmp !='\\'  && lpTmp >lpSrcFileName)
  18.         lpTmp = AnsiPrev(lpSrcFileName,lpTmp);
  19.     if (*lpTmp != ':' && *lpTmp != '\\')  //lpSrcFileName has no path part
  20.         {
  21.         lstrcpy( lpDestFileName, lpSrcFileName);
  22.         lpDestPath[0] = 0;
  23.         }
  24.     else
  25.         {
  26.         lstrcpy(lpDestFileName, lpTmp + 1);  // filename without path
  27.         cTmp = *(lpTmp + 1);
  28.         lstrcpy(lpDestPath,lpSrcFileName);
  29.         *(lpTmp+1) = cTmp;
  30.         lpDestPath[(lpTmp -lpSrcFileName) +1] = 0;
  31.         }
  32.     lpTmp = lpDestFileName + (long)lstrlen(lpDestFileName);
  33.     while (*lpTmp != '.'  && lpTmp >lpDestFileName)
  34.         lpTmp = AnsiPrev(lpDestFileName,lpTmp);
  35.     if (*lpTmp == '.' )  //lpDestFileName has  ext part
  36.         lstrcpy( lpDestExt, lpTmp);
  37.  
  38.     }
  39.  
  40.  
  41. // ***** ChangeDefExt
  42. // Change Default Extension to non-wildcard extension in Name
  43. void ChangeDefExt(LPSTR Ext, LPSTR Name)
  44.     {
  45.     LPSTR pTptr;
  46.     pTptr = Name;
  47.     while (*pTptr && *pTptr != '.') pTptr ++;
  48.     if (*pTptr)   // if really an extenstion
  49.         if (!_fstrchr(pTptr, '*')  && !_fstrchr(pTptr,'?') )  _fstrcpy(Ext, pTptr);
  50.     }
  51. // ******* AddExt(Name, Ext)
  52. // Add Ext to Name if none exists
  53. void AddExt(PSTR Name, PSTR Ext)
  54.     {
  55.     PSTR pTptr;
  56.     pTptr = Name;
  57.     while (*pTptr && *pTptr != '.') pTptr++;
  58.     if ( *pTptr !='.') strcat(Name, Ext);
  59. }
  60.  
  61.  
  62. // ******* ChangeExt(Name, Ext)
  63. // Change Ext to Name
  64. void ChangeExt(LPSTR Name, LPSTR Ext)
  65.     {
  66.     LPSTR pTptr;
  67.     pTptr = Name;
  68.     while (*pTptr && *pTptr != '.') pTptr++;
  69.     if ( *pTptr =='.') _fstrcpy(pTptr, Ext);
  70. }
  71.  
  72.  
  73.  
  74. LPSTR lstrchr (LPSTR str, char ch)
  75.       {
  76.       while (*str)
  77.              {
  78.              if (ch == *str)
  79.                     return str ;
  80.  
  81.              str = AnsiNext (str) ;
  82.              }
  83.       return NULL ;
  84.       }
  85.  
  86. // ********* lstrrchr
  87. // return LPSTR of last occurence of ch in str or NULL if not found
  88. LPSTR lstrrchr (LPSTR str, char ch)
  89.       {
  90.       LPSTR strl = str + lstrlen (str) ;
  91.  
  92.       do
  93.              {
  94.              if (ch == *strl)
  95.                     return strl ;
  96.  
  97.              strl = AnsiPrev (str, strl) ;
  98.              }
  99.       while (strl > str) ;
  100.  
  101.       return NULL ;
  102.       }
  103.  
  104.  
  105. // *** OKMsgBox
  106. void OKMsgBox( char *szCaption, char *szFormat, ...)
  107.     {
  108.     char szBuffer[256];
  109.     char *pArguments;
  110.     pArguments = (char *)&szFormat + sizeof szFormat;
  111.     vsprintf(szBuffer, szFormat, pArguments);
  112.     MessageBox( GetActiveWindow( ), szBuffer, szCaption, MB_OK);
  113.     }
  114.  
  115. // *** OKCancelMsgBox
  116. BOOL OKCancelMsgBox( char *szCaption, char *szFormat, ...)
  117.     {
  118.     char szBuffer[256];
  119.     char *pArguments;
  120.     pArguments = (char *)&szFormat + sizeof szFormat;
  121.     vsprintf(szBuffer, szFormat, pArguments);
  122.     int iret = MessageBox( GetActiveWindow( ), szBuffer, szCaption,
  123.                              MB_OKCANCEL | MB_ICONQUESTION);
  124.     if ( iret == IDOK )  return TRUE;
  125.     else                 return FALSE;
  126.     }
  127.  
  128. // *** HourGlass - toggle hourglass Icon
  129.  void HourGlass(HWND hWnd)
  130.     {
  131.     static HCURSOR hSaveCursor = NULL;
  132.     static hHourGlass = NULL;
  133.     if (hSaveCursor == NULL) // turn on hourglass
  134.         {
  135.         SetCapture(hWnd);
  136.         if (hHourGlass == NULL) hHourGlass = LoadCursor(NULL, IDC_WAIT );
  137.         hSaveCursor = SetCursor(hHourGlass);
  138.         }
  139.     else  // turn off hourglass
  140.         {
  141.         SetCursor( hSaveCursor);
  142.         ReleaseCapture();
  143.         hSaveCursor = NULL;
  144.         }
  145.     }
  146.  
  147. // ***  myError
  148. //error handling function for when CGMWindow being drawn
  149.  void
  150.  myError(const char *inMsg, const char *inMsg2, int errFlag)
  151.     {
  152.     HWND ActiveWindow = CGMWindow::hWindow; // NOTE: GetFocus() doesn't work here
  153.     CgmWindowPt CgmWin = (CgmWindowPt)GetPointer( ActiveWindow );  // invalid value if WM_CREATE not
  154.  
  155.     CgmWin->errors++;
  156.  
  157.     if (!errFlag) // severe error - overwrite any warnings
  158.         {
  159.         CgmWin->severe_error = TRUE;
  160.         // delete any existing error messages
  161.         DeleteSz(CgmWin->ErrMsg1 ); CgmWin->ErrMsg1 = NULL;
  162.         DeleteSz(CgmWin->ErrMsg2 ); CgmWin->ErrMsg2 = NULL;
  163.         }
  164.  
  165.     else // warning - don't overwrite first warnings
  166.         if (CgmWin->ErrMsg1) return;   // previous message exists
  167.  
  168.     CgmWin->ErrMsg1 = new  char[strlen(inMsg) + 1];
  169.     _fstrcpy(CgmWin->ErrMsg1, inMsg);
  170.     if (inMsg2 && *inMsg2)
  171.         {
  172.         CgmWin->ErrMsg2 = new  char[strlen(inMsg2) + 1];
  173.         _fstrcpy(CgmWin->ErrMsg2, inMsg2);
  174.         }
  175.     else { CgmWin->ErrMsg2 = new char; CgmWin->ErrMsg2 =0;}
  176.     }
  177.  
  178.  
  179.